package dao.search;

import bean.LessMoney;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import util.C3p0Util;

import java.sql.SQLException;
import java.util.List;

public class LessMonySearchDao {
    public List<LessMoney> findAll(){
        List<LessMoney> lessMoneySearchList = null;
        /*
            1.创建sql的执行器
                在不使用事务的情况下，需要指定一个数据源
                QueryRunner 对象处理连接以及关闭连接
         */
        QueryRunner runner = new QueryRunner(C3p0Util.getDs());
        String sql = "select * from t_lessMoney";

        try {
            /*
                会将数据封装到对应的对象集合中
             */
            lessMoneySearchList = runner.query(sql,new BeanListHandler<>(LessMoney.class));

        } catch (SQLException e) {
            e.printStackTrace();
        }
        return lessMoneySearchList;
    }

    public static void main(String[] args) {
        LessMonySearchDao lmsd = new LessMonySearchDao();
        List<LessMoney> inChecks = lmsd.findAll();
        System.out.println(inChecks.toString());
    }
}
